package org.jash.imdemo;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;

public class LoginActivity extends AppCompatActivity {
    private EditText username;
    private EditText password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        username = findViewById(R.id.username);
        password = findViewById(R.id.password);
        username.setText(getIntent().getStringExtra("username"));
        password.setText(getIntent().getStringExtra("password"));
        findViewById(R.id.login).setOnClickListener(v -> {
            EMClient.getInstance().login(username.getText().toString(), password.getText().toString(), new EMCallBack() {
                @Override
                public void onSuccess() {
                    runOnUiThread(() -> Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show());
                    startActivity(new Intent(LoginActivity.this, WechatActivity.class));
                    finish();
                }

                @Override
                public void onError(int code, String error) {
                    runOnUiThread(() -> Toast.makeText(LoginActivity.this, "登录失败, 原因: " + error, Toast.LENGTH_SHORT).show());
                }

                @Override
                public void onProgress(int progress, String status) {

                }
            });
        });

    }
}